﻿using B.S.Outsourcing.ErrorCode;
using B.S.Outsourcing.Infatructrue;
using B.S.Outsourcing.Writer.Api.Application.Command.OutsourcingArrivalOrderModel;
using MediatR;

namespace B.S.Outsourcing.Writer.Api.Application.CommandHandler.OutsourcingArrivalOrderModel
{
    public class UpdateOutSourcingArrivalCommandHandler : IRequestHandler<UpdateOutSourcingArrivalCommand, ApiResult<int>>
    {
        private readonly DBHelper1 dBHelper;

        public UpdateOutSourcingArrivalCommandHandler(DBHelper1 dBHelper)
        {
            this.dBHelper = dBHelper;
        }

        public async Task<ApiResult<int>> Handle(UpdateOutSourcingArrivalCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            var sql = $"update OutsourcingArrivalOrderModel set DocumentCode='{request.DocumentCode}',BusinessType='{request.BusinessType}',OutsourcingOrderNumber='{request.OutsourcingOrderNumber}',MaterialCode='{request.MaterialCode}',Remark='{request.Remark}',DocumentDate='{request.DocumentDate}',Operator='{request.Operator}',Supplier='{request.Supplier}',MaterialName='{request.MaterialName}',DocumentStatus='{request.DocumentStatus}',Auditor='{request.Auditor}',PlanOrderNumber='{request.PlanOrderNumber}',ArrivalQuantity='{request.ArrivalQuantity}',BusinessStatus='{request.BusinessStatus}',AuditDate='{request.AuditDate}',FollowOrderNumber='{request.FollowOrderNumber}',Warehouse='{request.Warehouse}',CreatedAt='{request.CreatedAt}',CreatedBy='{request.CreatedBy}',LastModifiedAt='{request.LastModifiedAt}',LastModifiedBy='{request.LastModifiedBy}',IsDelete='{request.IsDelete}',OrderDeliveryDate='{request.OrderDeliveryDate}' where id='{request.Id}'";
            var str = dBHelper.NonQuery(sql);
            if (str > 0)
            {
                result.Code = ApiEnums.成功;
                result.Message = "成功";
                result.Data = str;
            }
            else
            {
                result.Code = ApiEnums.失败;
                result.Message = "失败";
                result.Data = str;
            }
            return await Task.FromResult(result);
        }
    }
}
